<div class="from_main wrap" style="width: 480px;">

    <div class="panel panel-user">
        <div class="panel-heading">找回密码</div>
        <div class="panel-body">
            <?php if ($message): ?>
              <input type="hidden" id="errormsg" value="<?php echo $message;?>" />
            <?php endif; ?>
            <form id="resetpwdform" class="form-horizontal restpwdform" role="form" action="<?php echo url_for("user/resetpwd"); ?>" method="POST">
                <ul class="login_ul">
                    <li>
                        <label class="col-xs-3 control-label">用户名：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名">
                        </div>
                    </li>
                      <li>
                        <label class="col-xs-3 control-label">新密码：</label>
                        <div class="col-xs-8">
                            <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
                        </div>
                    </li>
                    <li>
                        <label class="col-xs-3 control-label">确认密码：</label>
                        <div class="col-xs-8">
                            <input type="password" class="form-control" id="password1" name="password1" placeholder="请确认密码">
                        </div>
                    </li>
                    <li>
                        <label class="col-xs-3 control-label">手机号：</label>
                        <div class="col-xs-8">
                            <input type="tel" class="form-control" id="mobile" name="mobile" placeholder="请输入手机号码">
                        </div>
                    </li>
                    <li>
                        <label class="col-xs-3 control-label">手机验证码：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="auth" name="auth">
                            <input type="button" class="btn btn-default" id="getauthcode" value="获取验证码" />
                        </div>
                    </li>
                    <li>
                        <label class="col-xs-3 control-label"></label>
                        <div class="col-xs-8">
                            
                            <button type="submit" class="btn btn-primary" id="resetpwd">确定</button>
                        </div>
                    </li>
                </ul>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
   $("#resetpwd").click(function (){
     
      var username =$("#username").val();
      var password =$("#password").val();
      var password1 =$("#password1").val();
      var mobile =$("#mobile").val();
      var auth =$("#auth").val();
      
      if(username=="" || password=="" || password1=="" || mobile=="" || auth==""){
        $.scojs_message("请填写完整信息", $.scojs_message.TYPE_ERROR);
        return false;
      }
      
      if(password != password1){
        $.scojs_message("两次密码输入不正确", $.scojs_message.TYPE_ERROR);
        return false;
      }
    });
    $(".main").addClass("projectlist");
    var message = $("#errormsg").val();
    if (message != "") {
        if (message == "1") {
            $.scojs_message("用户名不存在！", $.scojs_message.TYPE_ERROR);
           
        }else if (message == "2") {
            $.scojs_message("手机号码不正确", $.scojs_message.TYPE_ERROR);
           
        }else if (message == "3") {
            $.scojs_message("验证码错误", $.scojs_message.TYPE_ERROR);
        }else if (message == "4") {
            $.scojs_message("您的验证码已过期，请重新获取", $.scojs_message.TYPE_ERROR);
        }else if (message == "5") {
            $.scojs_message("验证码错误", $.scojs_message.TYPE_ERROR);
        }else if (message == "6") {
            $.scojs_message("手机号码不正确", $.scojs_message.TYPE_ERROR);
        }else if (message == "7") {
             $.scojs_message("密码修改成功，将自动跳转登录页", $.scojs_message.TYPE_OK);
             var url="<?php echo url_for("user/login"); ?>"
            var t = setTimeout("window.location.href = '"+url+"'", 4000);
           
        }
    } else {
        $("div[class='form-group has-error']").removeClass('has-error');
    }
</script>
<script type="text/javascript">
    $("#getauthcode").on('click', function () {
        var mobile = $("#mobile").val();
        var username = $("#username").val();
        if(mobile.length < 11){
           $.scojs_message("手机号码不正确", $.scojs_message.TYPE_ERROR);
            return false;
        }
        $.ajax({
             type: "POST",
             url: "<?php echo url_for('user/resetpwd_code'); ?>",
             data: "mobile=" + mobile+"&username="+username,
             dataType:"json",
             success: function(data){
                alert(data.result);
                 if(data.result == "error"){
                   $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }else{
                  $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                }
             }   
        });
    })
    
   
</script>